/*
    Copyright (c) 2008-2009, Prashanta Shrestha All Rights Reserved.
    Available under GNU Lesser General Public License >= 3.0 as published by the Free Software Foundation.
    see <http://www.gnu.org/licenses/>
*/
/*-------------------------------------------------------------------------------------
  CLASS : qDojo.dijix.Toaster
  ============================
  - A toaster widget to notify and display message for a few seconds with animation.  
  -------------------------------------------------------------------------------------*/
dojo.provide("qDojo.dijix.Toaster");

dojo.require("qDojo.dijix.Toast");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("dijit._Container");

dojo.declare("qDojo.dijix.Toaster", [dijit._Widget, dijit._Templated, dijit._Container] , {

	templateString: " <div style=\"height:auto;width:350px\" dojoAttachPoint=\"outerNode\">" + 
                        "<div dojoAttachPoint=\"containerNode\"></div>"+
	                " </div>",			
	
	// ===========================================================
	// Post Create Widget
	// -----------------------------------------------------------
	postCreate: function() 
	{			
		this.inherited(arguments);
		dojo.body().appendChild(this.domNode);
		var viewport = dijit.getViewport();
		var mb = dojo.marginBox(this.domNode);
		var left = Math.floor((viewport.l + (viewport.w - mb.w)/2));
		         			
	    var style = this.domNode.style;
	    style.visibility = "visible";
	    style.position = "absolute";														                                                                
	    style.top = "0px";
		style.left = left+"px";
		style.width ="300px";
	},					
	// ===========================================================
	// Show toaster
	// -----------------------------------------------------------
	show : function(type,message,title)
	{					
		var toast = new qDojo.dijix.Toast(); 				
		this.addChild(toast);
		toast.show(type,message,title);
	},
	// ===========================================================
	// Called by activated child (toast) of toaster
	// -----------------------------------------------------------
	childShown : function()
	{	
		var ch = this.getChildren();	   
        for(var i=0; i<ch.length; i++)
        {        
    	   if(ch[i].msgType==1)
    		   continue;
           else{
               ch[i].startCounter();
               break;
           }                         
        }   	   	   
	},
	// ===========================================================
	// Refresh other children - reposition
	// -----------------------------------------------------------
	refreshChildren: function(id)
	{   
		this.removeChild(dijit.byId(id));
	    var ch = this.getChildren();
	    for(var i=0; i<ch.length; i++)
        {
	    	if(ch[i].msgType == 0)
	        {
	    		ch[i].startCounter();
	            break;
	        }                               
        }    	   		                   		    
	}
});
